package com.study.java.jinjie.jihe.lianxi.three;

import java.util.HashMap;
import java.util.Map;

public class Score {

    Map<Integer,Student> studentmap;

    public Score(Map<Integer,Student> studentmap) {
        this.studentmap = studentmap;
    }

    //打印学生成绩
    public void studentprint() {
        if (studentmap != null) {
            System.out.print("序号");
            System.out.print("\t 学号");
            System.out.print(" \t姓名");
            System.out.print(" \t成绩\n");
            // 打印分割线
            System.out.println("_________________________");
            // 遍历学生集合
            int length = studentmap.size();  // 学生数量
            // 判断学生数量是否大于0
            if (length > 0) {
                // 根据学生长度使用for循环
                for (int i = 0; i < length; i++) {
                    // 从集合中获取学生
                    Student student = studentmap.get("i+1");

                    // 解析学生信息 打印
                    System.out.print(i + 1);  // 打印序号
                    System.out.print(" \t" + student.getNum());
                    System.out.print(" \t" + student.getName());
                    System.out.print(" \t" + student.getScore() + "\n");
                    // 打印分割线
                    System.out.println("----------------------------");
                }
            }
        }
    }




    //打印学生平均成绩
    public int pingjun(){
       int pingjun = 0;
        int l = studentmap.size();
        for (int i = 0; i <l ; i++) {
            Student student = studentmap.get(1+i);
            pingjun += student.getScore();
        }
        pingjun = pingjun/l;
        System.out.println("学生平均成绩:"+pingjun);
      return pingjun;
    }

    //打印学生最高成绩
    public  String zuigao(){
        int max = 0;
        String s = " ";
        int l = studentmap.size();
        for (int i = 0; i < l; i++) {
            Student student = studentmap.get(i+1);
            if (student.getScore()>max){
                max=student.getScore();
                s = student.getName();
            }
        }
        System.out.println("成绩最高学生为:"+ s);
        return s;
    }











}
